package com.ruoyi.web.controller.gxs;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gxs.domain.GxsScoreAdd;
import com.ruoyi.gxs.service.IGxsScoreAddService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 成绩导入Controller
 * 
 * @author 高晓松
 * @date 2024-03-02
 */
@RestController
@RequestMapping("/gxs/add")
public class GxsScoreAddController extends BaseController
{
    @Autowired
    private IGxsScoreAddService gxsScoreAddService;

    /**
     * 查询成绩导入列表
     */
//    @PreAuthorize("@ss.hasPermi('gxs:add:list')")
    @GetMapping("/list")
    public TableDataInfo list(GxsScoreAdd gxsScoreAdd)
    {
        startPage();
        List<GxsScoreAdd> list = gxsScoreAddService.selectGxsScoreAddList(gxsScoreAdd);
        return getDataTable(list);
    }

    /**
     * 导出成绩导入列表
     */
//    @PreAuthorize("@ss.hasPermi('gxs:add:export')")
    @Log(title = "成绩导入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GxsScoreAdd gxsScoreAdd)
    {
        List<GxsScoreAdd> list = gxsScoreAddService.selectGxsScoreAddList(gxsScoreAdd);
        ExcelUtil<GxsScoreAdd> util = new ExcelUtil<GxsScoreAdd>(GxsScoreAdd.class);
        util.exportExcel(response, list, "成绩导入数据");
    }

    /**
     * 获取成绩导入详细信息
     */
//    @PreAuthorize("@ss.hasPermi('gxs:add:query')")
    @GetMapping(value = "/{gxsId}")
    public AjaxResult getInfo(@PathVariable("gxsId") Long gxsId)
    {
        return success(gxsScoreAddService.selectGxsScoreAddByGxsId(gxsId));
    }

    /**
     * 新增成绩导入
     */
//    @PreAuthorize("@ss.hasPermi('gxs:add:add')")
    @Log(title = "成绩导入", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GxsScoreAdd gxsScoreAdd)
    {
        return toAjax(gxsScoreAddService.insertGxsScoreAdd(gxsScoreAdd));
    }

    /**
     * 修改成绩导入
     */
//    @PreAuthorize("@ss.hasPermi('gxs:add:edit')")
    @Log(title = "成绩导入", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GxsScoreAdd gxsScoreAdd)
    {
        return toAjax(gxsScoreAddService.updateGxsScoreAdd(gxsScoreAdd));
    }

    /**
     * 删除成绩导入
     */
//    @PreAuthorize("@ss.hasPermi('gxs:add:remove')")
    @Log(title = "成绩导入", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gxsIds}")
    public AjaxResult remove(@PathVariable Long[] gxsIds)
    {
        return toAjax(gxsScoreAddService.deleteGxsScoreAddByGxsIds(gxsIds));
    }

    //导入
    @Log(title = "成绩管理", businessType = BusinessType.IMPORT)
//    @PreAuthorize("@ss.hasPermi('system:user:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<GxsScoreAdd> util = new ExcelUtil<GxsScoreAdd>(GxsScoreAdd.class);
        List<GxsScoreAdd> gxsScoreAddList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = gxsScoreAddService.importScoreAdd(gxsScoreAddList, updateSupport, operName);
        return success(message);
    }

    //下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<GxsScoreAdd> util = new ExcelUtil<GxsScoreAdd>(GxsScoreAdd.class);
        util.importTemplateExcel(response, "学生成绩数据");
    }
}
